package yuan.deng.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;


public class MapperUtils {

    public static Object getMapper(Class<?> className){
        SqlSession sqlSession =null;
        try {
            InputStream is = Resources.getResourceAsStream("sqlConfig.xml");
            SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
            sqlSession = factory.openSession(true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Object mapper = sqlSession.getMapper(className);
        return mapper;
    }
}
